﻿using System;
namespace WebTraderLiteCL
{
    public class User
    {
        //class variables
        protected string AccountStatus;
        protected string AccountType;
        protected string Email;
        protected string FirstName;
        protected string LastName;
        protected DateTime RegistrationDate;
        protected string UserAddress;
        protected string UserID;
        protected string zipcode;
        protected string password;
        protected float accBalance;

        //initializer
        DBTransactions DB = new DBTransactions();


        public User()
        {

            this.AccountStatus = string.Empty;
            this.AccountType = string.Empty;
            this.Email = string.Empty;
            this.FirstName = string.Empty;
            this.LastName = string.Empty;
            //this.RegistrationDate = string.Empty;
            this.UserAddress = string.Empty;
            this.zipcode = string.Empty;
            this.password = string.Empty;


        }//end default constructor

        public User(string userID)
        {
            DB.OpenDB();
            this.UserID = userID;
            this.AccountStatus = DB.retrieveAccountStatus(userID);
            this.AccountType = DB.retrieveAccountType(userID);
            this.accBalance = DB.retrieveAccountBal(userID);
            this.Email = DB.retrieveEmail(userID);
            this.FirstName = DB.retrieveFirstName(userID);
            this.LastName = DB.retrieveLastName(userID);
            this.RegistrationDate = DB.retrieveRegistrationDate(userID);
            this.UserAddress = DB.retrieveUserAddress(userID);
            this.zipcode = DB.retrieveZipCode(userID);
            this.password = DB.retrievePswd(userID);
            DB.CloseDB();


        }//end default constructor

        //return 0 on success
        private int changePassword(string OldPass, string NewPass)
        {
            //Make a new DB instance then call password to see if the oldPass is correct and then have ask for a new password to be saved
            string DBPassword = DB.retrievePswd(this.UserID);
            if (DBPassword == OldPass)
            {
                DB.setPassword(this.UserID, NewPass);
                return 0;
            }//end if


            return 1;
        }//end changePassword
       
        public string getAccountStatus()
        {
            return AccountStatus;
        }//end getAccountStatus

        public string getAccountType()
        {
            return AccountType;
        }//end getAccountType

        public string getEmail()
        {
            return Email;
        }//end getEmail

        public string getFirstName()
        {
            return FirstName;
        }//end getFirstName

        public string getLastName()
        {
            return LastName;
        }//end getLastName

        public DateTime getRegistrationDate()
        {
            return RegistrationDate;
        }//end getRegistrationDate

        public string getUserAddress()
        {
            return UserAddress;
        }//end getUserAddress
        public string getzipCode()
        {
            return this.zipcode;
        }
        public float getAccBalance()
        {
            return this.accBalance;
        }
        public string getaccStatus()
        {
            return this.AccountStatus;
        }
        public string getaccType()
        {
            return this.AccountType;
        }
        public string getPassword()
        {
            return this.password;
        }
        public string getUserID()
        {
            return this.UserID;
        }//end getUserID

        //return 0 on success
        public int setEmail(string NewEmail)
        {
            Email = NewEmail;
            return 0;
        }//end setEmail

        //return 0 on success
        public int setFirstName(string NewFirstName)
        {
            FirstName = NewFirstName;
            return 0;
        }//end setFirstName

        //return 0 on success
        public int setLastName(string NewLastName)
        {
            LastName = NewLastName;
            return 0;
        }//end setLastName

        //return 0 on success
        public int setUserAddress(string NewUserAddress)
        {
            UserAddress = NewUserAddress;
            return 0;
        }//end setUserAddress

        public int setUserID(string NewUserID)
        {
            UserID = NewUserID;
            return 0;
        }//end setUserAddress
        public void setPassword(string pass)
        {
            this.password = pass;
        }
        public void setzipCode(string zip)
        {
            this.zipcode = zip;
        }
        public void setAccType(string type)
        {
            this.AccountType = type;
        }
        public void setAccStatus(string status)
        {
            this.AccountStatus = status;
        }
        public void setAccBalance(float bal)
        {
            this.accBalance = bal;
        }
    }//end User Class
}